import cv2
import numpy as np
import os
import sys

id = sys.argv[1]
path = "./register_picture/" + id

# 加载图片
'''os.listdir读取目录下所有文件名，
os.path.join把目录下路径和文件名结合起来得到绝对路径'''
imagePaths = [os.path.join(path, f) for f in os.listdir(path)]
faceSample = []

for imagePath in imagePaths:
    img = cv2.imread(imagePath, cv2.IMREAD_GRAYSCALE) # 读人灰度图片
    faceSample.append(img)

# 加载标签
ids = []
ids.append(int(id))
ids = np.array(ids*len(faceSample))
# 初始化
recognizer = cv2.face.LBPHFaceRecognizer.create()
# 训练
recognizer.train(faceSample, ids)
recognizer.write('./model/' + id + '.yml')
